//
//  EvaluateViewController.m
//  PhotoSelector
//
//  Created by 洪雯 on 2017/1/12.
//  Copyright © 2017年 洪雯. All rights reserved.
//

#import "EvaluateViewController.h"
#import "BRPlaceholderTextView.h"
#import "UIImageView+WebCache.h"
#define iphone4 (CGSizeEqualToSize(CGSizeMake(320, 480), [UIScreen mainScreen].bounds.size))
#define iphone5 (CGSizeEqualToSize(CGSizeMake(320, 568), [UIScreen mainScreen].bounds.size))
#define iphone6 (CGSizeEqualToSize(CGSizeMake(375, 667), [UIScreen mainScreen].bounds.size))
#define iphone6plus (CGSizeEqualToSize(CGSizeMake(414, 736), [UIScreen mainScreen].bounds.size))
//默认最大输入字数为  kMaxTextCount  300
#define kMaxTextCount 300
#define HeightVC [UIScreen mainScreen].bounds.size.height//获取设备高度
#define WidthVC [UIScreen mainScreen].bounds.size.width//获取设备宽度

@interface EvaluateViewController ()<UIScrollViewDelegate,UITextViewDelegate>
{
    float _TimeNUMX;
    float _TimeNUMY;
    int _FontSIZE;
    float allViewHeight;
    //备注文本View高度
    float noteTextHeight;
    NSMutableArray *dataPicArr;

}

/**
 *  主视图-
 */
@property (nonatomic, strong) UIScrollView *mianScrollView;

//背景
@property (nonatomic, strong) UITextField *titleField;
@property (nonatomic, strong) UITextView *contentTextView;
@property (nonatomic , strong)UIButton *addImageBtn; // 添加图片用btn

//文字个数提示label
@property (nonatomic, strong) UILabel *textNumberLabel;
//图片
@property (nonatomic,strong) UIImageView *photoImageView;
@property (nonatomic, strong) NSMutableDictionary *productParams;

@property (nonatomic,strong) NSMutableArray * photoArr;




@end

@implementation EvaluateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createUI];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"发布";
    UIButton *searchBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, screenScale(70), screenScale(40))];
    
    [searchBtn setTitle:@"发布" forState:UIControlStateNormal];
    [searchBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    searchBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [searchBtn addTarget:self action:@selector(ReleaseBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *rightItme = [[UIBarButtonItem alloc]initWithCustomView:searchBtn];
    self.navigationItem.rightBarButtonItem = rightItme;

    
    ///照片
    self.photoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20*_TimeNUMX, 20*_TimeNUMY, 80*_TimeNUMX, 90*_TimeNUMY)];

    [self.view addSubview:self.photoImageView];

    [self updateViewsFrame];
    
    _TimeNUMX = [self BackTimeNUMX];
    _TimeNUMY = [self BackTimeNUMY];
    self.titleField = [[UITextField alloc] init];
    [self.view addSubview:self.titleField];
    self.titleField.placeholder = @"请输入标题";
    self.titleField.font = [UIFont systemFontOfSize:15];
    [self.titleField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).with.offset(17);
        make.left.equalTo(self.view).with.offset(12);
        make.right.equalTo(self.view).with.offset(-12);
        make.height.offset(16);
        
    }];
    [self.titleField setBorderStyle:UITextBorderStyleNone];
    
    UILabel *labelGary = [[UILabel alloc] init];
    [self.view addSubview:labelGary];
    labelGary.backgroundColor = getThreadColor();
    [labelGary mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleField.mas_bottom).with.offset(13);
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.height.offset(1);
        
        
    }];
    
    self.contentTextView = [[UITextView alloc] init];
    [self.view addSubview:self.contentTextView];
    self.contentTextView.font = [UIFont systemFontOfSize:15];
    [self.contentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).with.offset(12);
        make.right.equalTo(self.view).with.offset(-12);
        make.top.equalTo(labelGary.mas_bottom).with.offset(13);
        make.height.offset(100);
        
    }];
    self.contentTextView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    UILabel *placeHolderLabel = [[UILabel alloc] init];
    placeHolderLabel.text = @"请输入内容...";
    placeHolderLabel.numberOfLines = 0;
    placeHolderLabel.font = [UIFont systemFontOfSize:15];
    
    placeHolderLabel.textColor = getColor(@"b6b6b6");
    [placeHolderLabel sizeToFit];
    [self.contentTextView addSubview:placeHolderLabel];
    
    [self.contentTextView setValue:placeHolderLabel forKey:@"_placeholderLabel"];

    
    
    
}

- (void)createUI{
    
    _mianScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 160, WidthVC, HeightVC+230)];
    _mianScrollView.contentSize =CGSizeMake(WidthVC, HeightVC+230);
    _mianScrollView.bounces =YES;
    _mianScrollView.showsVerticalScrollIndicator = false;
    _mianScrollView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_mianScrollView];
    [_mianScrollView setDelegate:self];
    self.showInView = _mianScrollView;
    
    UIView *view = [[UIView alloc] init];
    [self.view addSubview:view];
    NSInteger hri = DEF_SCREEN_HEIGHT - 160 - 88 - ([UIScreen mainScreen].bounds.size.width-100);
    
    view.backgroundColor = [UIColor whiteColor];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.bottom.equalTo(self.view);
        make.height.offset(hri);
        
    }];
    
    /** 初始化collectionView */
    [self initPickerView];
    
   
}



/**
 *  界面布局 frame
 */
- (void)updateViewsFrame{
    
    //photoPicker
    [self updatePickerViewFrameY:1];
    
    
}
/**
 *  恢复原始界面布局
 */


- (void)pickerViewFrameChanged{
    [self updateViewsFrame];
}



#pragma mark - UIScrollViewDelegate
//用户向上偏移到顶端取消输入,增强用户体验
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.y < 0) {
        [self.view endEditing:YES];
    }
}




#pragma mark 返回不同型号的机器的倍数值
- (float)BackTimeNUMX {
    float numX = 0.0;
    if (iphone4) {
        numX = 320 / 375.0;
        return numX;
    }
    if (iphone5) {
        numX = 320 / 375.0;
        return numX;
    }
    if (iphone6) {
        return 1.0;
    }
    if (iphone6plus) {
        numX = 414 / 375.0;
        return numX;
    }
    return numX;
}
- (float)BackTimeNUMY {
    float numY = 0.0;
    if (iphone4) {
        numY = 480 / 667.0;
        _FontSIZE = -2;
        return numY;
    }
    if (iphone5) {
        numY = 568 / 667.0;
        _FontSIZE = -2;
        return numY;
    }
    if (iphone6) {
        _FontSIZE = 0;
        return 1.0;
    }
    if (iphone6plus) {
        numY = 736 / 667.0;
        _FontSIZE = 2;
        return numY;
    }
    return numY;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
